define(["jquery", "easy-admin"], function ($, ea) {

    var init = {
        table_elem: '#currentTable',
        table_render_id: 'currentTableRenderId',
        index_url: 'orders/index',
        index1_url: 'orders/index1',
        add_url: 'orders/add',
        edit_url: 'orders/edit',
        delete_url: 'orders/delete',
        export_url: 'orders/export',
        modify_url: 'orders/modify',
        ratio_url: 'orders/ratio',
        view_url: 'orders/view',
        // settlement_url: 'orders/settlement',
        // wage_url: 'orders/wage',
    };

    var Controller = {

        index: function () {
            ea.table.render({
                init: init,
                toolbar: ['refresh', 'export',],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '编号', width: 100, templet: function (d) {
                            if (d.id) {
                                return '<a class="layui-table-cell" style="text-decoration: underline;cursor: pointer;" data-open="orders/view?id=' + d.id + '">' + d.id + '</a>';
                            }
                            return '';
                        }
                    },
                    {field: 'true_name', title: '员工', width:100, search: true},
                    {field: 'name', title: '客户', width:100, search: false},
                    {field: 'state', search: false, width:150, title: '订单状态', templet: function (d) {
                            return '<div class="layui-table-cell" style="color: green;">进行中</div>';
                        }
                    },
                    {field: 'total_amount', title: '成交金额', search: false},
                    {field: 'pay_amount', title: '已收金额', search: false},
                    {field: 'ratio', title: '提成比例', search: false, templet: ea.table.percent},
                    {field: 'create_time', title: '审核时间', search: 'range'},
                    {
                        width: 150,
                        title: '操作',
                        templet: ea.table.tool,
                        operat: [
                            [{
                                text: '编辑',
                                url: init.edit_url,
                                method: 'open',
                                auth: 'edit',
                                class: 'layui-btn layui-btn-xs layui-btn-success',
                                extend: 'data-full="true"',
                            }]
                        ]
                    }

                ]],
            });

            ea.listen();
        },
        index1: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'orders/index1',
                },
                toolbar: ['refresh', 'export',],
                limit: 1000,
                limits: [1000, 1500, 2000, 2500, 5000, 10000],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '编号', width: 100, templet: function (d) {
                            if (d.id) {
                                return '<a class="layui-table-cell" style="text-decoration: underline;cursor: pointer;" data-open="orders/view?id=' + d.id + '">' + d.id + '</a>';
                            }
                            return '';
                        }
                    },
                    {field: 'true_name', title: '员工', width:100, search: true},
                    {field: 'name', title: '客户', width:100},
                    {field: 'state', search: false, width:150, title: '订单状态', templet: function (d) {
                            return '<div class="layui-table-cell" style="color: red;">已完成</div>';
                        }
                    },
                    {field: 'total_amount', title: '成交金额', search: false},
                    {field: 'pay_amount', title: '已收金额', search: false},
                    {field: 'ratio', title: '提成比例', width:100, search: false, templet: ea.table.percent},
                    {field: 'create_time', title: '审核时间', search: 'range'},
                ]],
            });
            ea.listen();
        },
        index2: function () {
            ea.table.render({
                init: {
                    table_elem: '#currentTable',
                    table_render_id: 'currentTableRenderId',
                    index_url: 'orders/index2',
                },
                toolbar: ['refresh', 'export',],
                limit: 1000,
                limits: [1000, 1500, 2000, 2500, 5000, 10000],
                cols: [[
                    {type: 'checkbox'},
                    {field: 'id', title: '编号', width: 100, templet: function (d) {
                            if (d.id) {
                                return '<a class="layui-table-cell" style="text-decoration: underline;cursor: pointer;" data-open="orders/view?id=' + d.id + '">' + d.id + '</a>';
                            }
                            return '';
                        }
                    },
                    {field: 'true_name', title: '员工', width:100, search: true},
                    {field: 'name', title: '客户', width:100},
                    {field: 'state', search: false, width:150, title: '订单状态', templet: function (d) {
                            return '<div class="layui-table-cell" style="color: #009688;">已结算</div>';
                        }
                    },
                    {field: 'total_amount', title: '成交金额', search: false},
                    {field: 'pay_amount', title: '已收金额', search: false},
                    {field: 'ratio', title: '提成比例', width:100, search: false, templet: ea.table.percent},
                    {field: 'ratio_amount', title: '项目提成', search: false},
                    {field: 'ratio_time', title: '结算时间', search: 'range'},
                ]],
            });
            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});